﻿using System;

namespace MessagePack.Formatters
{
	// Token: 0x02000032 RID: 50
	public class NullableInt32Formatter : IMessagePackFormatter<int?>
	{
		// Token: 0x060000B7 RID: 183 RVA: 0x00003F94 File Offset: 0x00002394
		private NullableInt32Formatter()
		{
		}

		// Token: 0x060000B8 RID: 184 RVA: 0x00003F9C File Offset: 0x0000239C
		public int Serialize(ref byte[] bytes, int offset, int? value, IFormatterResolver formatterResolver)
		{
			if (value == null)
			{
				return MessagePackBinary.WriteNil(ref bytes, offset);
			}
			return MessagePackBinary.WriteInt32(ref bytes, offset, value.Value);
		}

		// Token: 0x060000B9 RID: 185 RVA: 0x00003FC4 File Offset: 0x000023C4
		public int? Deserialize(byte[] bytes, int offset, IFormatterResolver formatterResolver, out int readSize)
		{
			if (MessagePackBinary.IsNil(bytes, offset))
			{
				readSize = 1;
				return null;
			}
			return new int?(MessagePackBinary.ReadInt32(bytes, offset, out readSize));
		}

		// Token: 0x04000026 RID: 38
		public static readonly NullableInt32Formatter Instance = new NullableInt32Formatter();
	}
}
